package com.starchen.optimalselection.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starchen.optimalselection.common.model.QueryParamsForm;
import com.starchen.optimalselection.common.model.ResultPage;
import com.starchen.optimalselection.common.utils.PageUtils;
import com.starchen.optimalselection.product.mapper.BrandMapper;
import com.starchen.optimalselection.common.service.BrandService;
import com.starchen.optimalselection.common.model.Brand;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Override
    public ResultPage queryPage(QueryParamsForm brandQueryVo) {
        String key =  brandQueryVo.getKeyword();
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        if(StringUtils.hasText(key)){
            queryWrapper.like("name",key);
        }

        IPage<Brand> page = baseMapper.selectPage(PageUtils.getPage(brandQueryVo.getPageIndex(),brandQueryVo.getPageSize()), queryWrapper);
        return new ResultPage(page);
    }

}